#
# Do not alter this file, create a copy with 
# a different name and modify that. Keep the extension .py
# otherwise it cannot be imported.
#
#
# Data processing configuration module set up to 
# process the drosophila demo data included in the distribution.
# 
# In this file capitalized attributes must be present (GeneTrack
# will check for their presence).
#
# All attributes may be written out as text but we use
# simple python functions to be able to generate them.
# This makes changing the attributes (such as labels) 
# a lot less error prone.
#

#
# Imports some common sense defaults from library/settings.py
#
from settings import *
from atlas import join_paths

#
# Turns various execution steps on or off.
#
LOADER_ENABLED    = True
FITTER_ENABLED    = True
PREDICTOR_ENABLED = True
EXPORTER_ENABLED  = True

#
# directory setup, must be a strings containing the full path to a directory 
# currently is set to the default home, relative to the main distribution.
# helper functions are used below
#

# experiment name
expname  = 'fancydmel'

# the experiment directory, located in library/fancydmel
expdir = get_experiment_dir (expname)

# the database directory, located in library/fancydmel/db
dbdir = join_paths(expdir, 'db')

# setting up the databases
HDF_DATABASE = get_hdf_file( path=dbdir, name=expname)
SQL_URI      = get_sqlite_uri(path=dbdir, name=expname)

# input data (for data loading) comes from this file.
DATA_FILE =  join_paths( expdir, "data", "dmel-genetrack-input.txt" )

# override DATA_SIZE from settings to make it larger
DATA_SIZE = 10**7

# Fitting tolerance. This and the EXCLUSION_ZONE are the most important 
# fitting parameters as they may substantially alter the prediction results.
#
# It is the distance in bp over which the fitting curve falls to 1/2.
# Noisier  data needs larger values, must be experimented with, 
# for a good visual example of what SIGMA does see the
# plots in the Documentation -> Quick Overview.
#
SIGMA = 20

#
# Distance over which the fitting function is computed over.
# For normal fitting it should be a few SIGMA wide. Most of the time
# may be left as is.
#
WIDTH = SIGMA * 5

#
# HDF labels for data, fitted data.
# Peak labels go into the SQL database.
#
DATA_LABEL = "H2AZ"

# Will make a fit label -> H2AZ-SIGMA-20
FIT_LABEL  = get_fit_label(label=DATA_LABEL, sigma=SIGMA)

# Will make a prediction label -> PRED-H2AZ-SIGMA-20
PEAK_LABEL = get_pred_label(label=DATA_LABEL, sigma=SIGMA)

#
# Peak detection parameters, the exclusion zone is the region over 
# which only one peak may be present.
#
EXCLUSION_ZONE = 147

#
# The expected position of the feature relative
# to the peak that is detected. For a nucleosome
# detection we extend equally in both directions.
#
LEFT_SHIFT  = EXCLUSION_ZONE/2
RIGHT_SHIFT = EXCLUSION_ZONE/2

#
# Data export.
#
# Note that you can export from the database as well
# with simple select queries, this feature is for convenience
# files that go into the /html/static/download folder will
# be visible and downloadable via the webserver.
#
EXPORT_LABELS  = [ PEAK_LABEL ]

# This comes from the settings
EXPORT_DIR     = DOWNLOAD_DIR

#
# Functions specification, by overriding these one
# may completely change what the server does
#

# Specifies the data file format parser.
from mod454.loader import loader as LOADER

# Specifies the data fitter.
from mod454.fitter import fitter as FITTER

# Specifies the data predictor.
from mod454.predictor import predictor as PREDICTOR

# Specfies the data exporter.
from atlas.commands import exporter as EXPORTER

#
# For convenience this below will autoload files with the ORF features.
# The file must be tab separated, see the library/yeast/data/dmel-ORF-features.txt 
# file for the required columns.
#

from atlas import util
util.debug_on()

datapath = join_paths(expdir, "data")
fnames = [ 
    #"motif_for_genetrack2.tab", # this line will take a long time to load -> 7 million motifs
    "other_features_for_genetrack.tab",
    "PolII_nucl_for_genetrack.tab",
    "GAF_for_genetrack.tab",
    "Bulk_nucl_for_genetrack.tab",
    "ORF_for_genetrack.tab",
]

load_feature_files( sql_uri=SQL_URI, path=datapath, fnames=fnames, clobber=False, drop_indices=False)
